<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>{&SITE_TITLE}</title>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/jquery.form.js"></script>	
	<link href="__PUBLIC__/admin/css/layout.css" rel="stylesheet" type="text/css" />
	</head>
	<body>
		<div id="container">
			<form action="__APP__/Popedom/savecommision" method="POST" />
			<table class="tableborder" width="100%">
				<tbody>
					<tr class="top">
						<td class="border" colspan="2"></td>
					</tr>
					<tr>
						<th class="header" colspan="2">权限管理</th>
					</tr>
					<tr class="label">
						<th>说明</th>
						<th>设置</th>
					</tr>
					<tr class="cell">
						<td class="altbg1" style="width:150px;">
							<b>用户组:</b>
						</td>
						<td class="altbg2" style="padding:10px">
							<select style="width:150px;" name="grouplist" id="grouplist" onchange="selectMenu(this.value)">
								<option value="0">请选择</option>
							    <volist id="vo" name="grouplist">
							    <php>if($vo['id']==$groupid){</php>
									<option value="{$vo.id}" selected>{$vo.name}</option>
								<php>}else{</php>
									<option value="{$vo.id}">{$vo.name}</option>
								<php>}</php>
								</volist>
							</select>
						</td>
					</tr>
					<tr class="cell">
						<td class="altbg1" style="width:150px;">
							<b>管理类型:</b>
						</td>
						<td class="altbg2" style="padding:10px">
							<select style="width:150px;" name="type" id="type" onchange="selectType(this.value)">
								<option value="admin" <eq name='type' value="admin">selected</eq> >后台权限配置</option>
								<option value="apps"  <eq name='type' value="apps">selected</eq> >APP应用管理</option>
							</select>
						</td>
					</tr>		
		
<php>if($type=='admin'){</php>
					<tr class="cell">
						<td class="altbg1" style="width:150px;">
							<b>菜单:</b>
						</td>
						<td class="altbg2" id="menulist" style="padding:10px;">
						<ul class="list">
						<volist id="vo" name="nodelist">
						 <php>if(in_array($vo['id'],$userNode['menu'])){</php>
							<li><input type="checkbox" name="popedom[{$vo.id}]" value="{$vo.id}" checked onclick="selectModel(this,{$vo.id},'{$vo.title}')"> {$vo.title}</li>
						<php>}else{</php>
							<li><input type="checkbox" name="popedom[{$vo.id}]" value="{$vo.id}" onclick="selectModel(this,{$vo.id},'{$vo.title}')"> {$vo.title}</li>
						<php>}</php>	
						</volist>
						</ul>
						</td>
					</tr>
					
					<tr class="cell">
						<td class="altbg1" style="width:150px;">
							<b>Model:</b>
						</td>
						<td class="altbg2" id="modellist" >
							<volist id="vo" name="nodelist">
							<php>if(in_array($vo['id'],$userNode['menu'])){</php>
								<fieldset id="fieldset_{$vo.id}">
								<legend>{$vo.title}</legend>
									<ul class="list" id="list_{$vo.id}">
										<sublist name="vo['child']" id="sub">
											<php>if(in_array($sub['id'],$userNode['model'])){</php>
												<li><input type="checkbox" name="popedom[{$sub.pid}][{$sub.id}]" value="{$sub.id}" checked onclick="selectAction(this,this.value,'{$sub.title}')"> {$sub.title}</li>
											<php>}else{</php>
												<li><input type="checkbox" name="popedom[{$sub.pid}][{$sub.id}]" value="{$sub.id}" onclick="selectAction(this,this.value,'{$sub.title}')"> {$sub.title}</li>
											<php>}</php>
										</sublist>
									</ul>
							 	</fieldset>
							 <php>}</php>
							</volist>
						</td>
					</tr>

					<tr class="cell">
						<td class="altbg1" style="width:150px;">
							<b>Action:</b>
						</td>
						<td class="altbg2" id="actionlist" >
							<volist id="vo" name="nodelist">
							<php>if(in_array($vo['id'],$userNode['menu'])){</php>
							  <sublist name="vo['child']" id="model">
							    <php>if(in_array($model['id'],$userNode['model'])){</php>
								<fieldset id="fieldset_{$model.id}" level="{$vo.id}">
								<legend>{$model.title}</legend>
									<ul class="list" id="list_{$model.id}">
										<sublist name="model['child']" id="sub">
											<php>if(in_array($sub['id'],$userNode['action'])){</php>
										<li><input type="checkbox" name="popedom[{$vo.id}][{$sub.pid}][]" value="{$sub.id}" checked /> {$sub.title}</li>
											<php>}else{</php>
										<li><input type="checkbox" name="popedom[{$vo.id}][{$sub.pid}][]" value="{$sub.id}" /> {$sub.title}</li>
											<php>}</php>
										</sublist>
									</ul>
							 	</fieldset>
							 	 <php>}</php>
							 	</sublist>
							 <php>}</php>
							</volist>
						</td>
					</tr>										
<php>}else{</php>

					<tr class="cell">
						<td class="altbg1" style="width:150px;">
							<b>应用列表:</b>
						</td>
						<td class="altbg2" id="menulist" style="padding:10px;">
						<ul class="list">
						<volist id="vo" name="nodelist">
						 <php>if(in_array($vo['id'],$userNode['model'])){</php>
							<li><input type="checkbox" name="popedom[{$vo.id}]" value="{$vo.id}" checked onclick="selectAction(this,{$vo.id},'{$vo.title}')"> {$vo.title}</li>
						<php>}else{</php>
							<li><input type="checkbox" name="popedom[{$vo.id}]" value="{$vo.id}" onclick="selectAction(this,{$vo.id},'{$vo.title}')"> {$vo.title}</li>
						<php>}</php>	
						</volist>
						</ul>
						</td>
					</tr>

					<tr class="cell">
						<td class="altbg1" style="width:150px;">
							<b>Action:</b>
						</td>
						<td class="altbg2" id="actionlist" >
							<volist id="vo" name="nodelist">
							<php>if(in_array($vo['id'],$userNode['model'])){</php>
								<fieldset id="fieldset_{$vo.id}" level="{$vo.id}">
								<legend>{$vo.title}</legend>
									<ul class="list" id="list_{$model.id}">
										<sublist name="vo['child']" id="sub">
											<php>if(in_array($sub['id'],$userNode['action'])){</php>
										<li><input type="checkbox" name="popedom[0][{$sub.pid}][]" value="{$sub.id}" checked /> {$sub.title}</li>
											<php>}else{</php>
										<li><input type="checkbox" name="popedom[0][{$sub.pid}][]" value="{$sub.id}" /> {$sub.title}</li>
											<php>}</php>
										</sublist>
									</ul>
							 	</fieldset>
							 <php>}</php>
							</volist>
						</td>
					</tr>


<php>}</php>
					<tr>
						<td class="footer" colspan="2">
							<input type="submit" class="button" value="提交" />
		
						</td>
					</tr>
					<tr class="bottom">
						<td class="border" colspan="5">&nbsp;</td>
					</tr>
				</tbody>
			</table>
		  </form>
		</div>
	</body>
</html>
<style>
.list{
	 list-style-type:none; list-style-position:inside;

	 display:block;
}
.list li{
	width:100px;
	float:left;
}
fieldset{
	padding:5px;
	margin:5px;
	border:1px solid #C4E5F6;
	width:auto;
}
#modellist fieldset{
	float:left;
}
</style>		
<script type="text/javascript">
var groupid = '{:$_GET['groupid']}';
var type    = '{:$_GET['type']}';

function selectMenu(id){
	if(type==''){
		location.href='__APP__/Popedom/commision/groupid/'+id;
	}else{
		location.href='__APP__/Popedom/commision/groupid/'+id+'/type/'+type;
	}
}

function selectType(type){
	location.href='__APP__/Popedom/commision/groupid/'+groupid+'/type/'+type;
}
	
//选择model
function selectModel(obj,id,nodeName){
	if(obj.checked){
		if($("#fieldset_"+id).size()==0){
			$('#modellist').append(addNode(nodeName,id,0));
		}else{
			$("#list_"+id).html('<li><img src="../Public/images/loading.gif" style="height:15px;"> Loading...</li>');
		}
		$.post('__APP__/Popedom/getInfoList',{type:'modellist',id:id,groupid:$('#grouplist').val()},function(txt){
				$("#list_"+id).html(txt);
		});
	}else{
		 $("#fieldset_"+id).fadeOut("fast",function(){
		 	$("#fieldset_"+id).remove();
		 	
			$.each( $("fieldset[level='"+id+"']"), function(i, n){
			  $(this).remove();
			}); 				
		 }); 
	}
}
   
//选择action
function selectAction(obj,id,nodeName,level){
	if(obj.checked){
		if($("#fieldset_"+id).size()==0){
			$('#actionlist').append(addNode(nodeName,id,level));
		}else{
			$("#list_"+id).html('<li><img src="../Public/images/loading.gif" style="height:15px;"> Loading...</li>');
		}
		$.post('__APP__/Popedom/getInfoList',{type:'actionlist',id:id,groupid:$('#grouplist').val()},function(txt){
				$("#list_"+id).html(txt);
		});
	}else{
		 $("#fieldset_"+id).fadeOut("fast",function(){
				$("#fieldset_"+id).remove();
		 }); 
	}	
}
   
//保存权限
function savecommision(){
	var data = $("#savecommision").formToArray(); 
	$.post("__APP__/Popedom/savecommision",data,function(txt){
		alert(txt);	
	});	
}
   
//添加node
function addNode(nodename,id,level){
		var html='<fieldset id="fieldset_'+id+'" level="'+level+'">'
				+'<legend>'+nodename+'</legend>'
				+'	<ul class="list" id="list_'+id+'">'
				+'  	<li><img src="../Public/images/loading.gif" style="height:15px;"> Loading...</li>'
				+'	</ul>'
		 		+'</fieldset>';
		return html; 		
}
</script>